package Zadanie7;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;


public class VectorM implements Serializable {
	
	double[] rows;
	double[] colums;
	double sum;
	int n;
	int m;
	
	VectorM(double[] rows, double[] colums, int m, int n) {
		
		this.rows = rows;
		this.colums = colums;
		this.n = n;
		this.m = m;
		sum = 0;
	}
	
	VectorM(double rows[], int m, int n) {
		this.rows = rows;
		this.n = n;
		this.m = m;
		sum = 0;
	}
	
	public void setColums(double[] colums) {
		
		this.colums = colums;
		
	}
	
	public double[] getRows() {
		return rows;
	}
	
	public double[] getColumn() {
		return colums;
	}
	
	public void multiply() {
		
		
		
		for(int i=0; i<rows.length; i++) {
			sum += rows[i] * colums[i];
		}
		
		rows = null;
		colums = null;
		
	}
	
	public static VectorM deserialize(byte[] data) {
	    ByteArrayInputStream in = new ByteArrayInputStream(data);
	    ObjectInputStream is;
		try {
			is = new ObjectInputStream(in);
			 return (VectorM) is.readObject();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static byte[] serialize(Object obj) {
	    ByteArrayOutputStream out = new ByteArrayOutputStream();
	    ObjectOutputStream os;
		try {
			os = new ObjectOutputStream(out);
			 os.writeObject(obj);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	   
	    return out.toByteArray();
	}
	
	public String toString() {
		
		return "Rows: " + rows.length + " Column: " + colums.length;
		
	}
	
	public int getM() {
		return m;
	}
	
	public int getN() {
		return n;
	}

}
